home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / apport / testsuite / test-apport < prev    next >
Encoding:
Text File  |  2009-04-06  |  20.6 KB  |  555 lines

  1. #!/usr/bin/python
  2.  
  3. import tempfile, shutil, os.path, os, subprocess, signal, time, stat, sys
  4. import resource, errno
  5. import apport.fileutils
  6.  
  7. test_executable = '/bin/cat'
  8. test_package = 'coreutils'
  9. test_source = 'coreutils'
  10.  
  11. required_fields = ['ProblemType', 'CoreDump', 'Date', 'ExecutablePath',
  12.     'ProcCmdline', 'ProcEnviron', 'ProcMaps', 'Signal', 'UserGroups']
  13.  
  14. ifpath = os.path.expanduser(apport.report._ignore_file)
  15. orig_ignore_file = None
  16.  
  17. def run(argv, msg=None, stdout=False):
  18.     '''Execute the given program with arguments and verify that it exits
  19.     successfully. 
  20.     
  21.     Set stdout to True to see the program's standard output. msg is the
  22.     assertion error message in case of failure.'''
  23.  
  24.     if stdout:
  25.         result = subprocess.call(argv)
  26.     else:
  27.         result = subprocess.call(argv, stdout=subprocess.PIPE)
  28.     assert result == 0, msg + ' [cwd: %s]' % os.getcwd()
  29.  
  30.  
  31. def clean_preload_lib():
  32.     print '* cleaning preloadlib directory'
  33.     run(['make', '-C', 'preloadlib', 'clean'], 'Cleaning preloadlib directory')
  34.  
  35. def build_preload_lib():
  36.     print '* Building preload library with local parameters'
  37.     run(['make', '-C', 'preloadlib', 'AGENTPATH=%s' % os.path.join(os.getcwd(),
  38.         'bin', 'apport')], 'Building preloadlib')
  39.  
  40. def enable_preloadlib():
  41.     assert os.access('preloadlib/libapport.so', os.X_OK)
  42.     os.environ['LD_PRELOAD'] = os.path.join(os.getcwd(), 'preloadlib', 'libapport.so')
  43.  
  44. def create_test_process(check_running=True):
  45.     assert os.access(test_executable, os.X_OK), test_executable + ' is not executable'
  46.     if check_running:
  47.         assert subprocess.call(['pidof', test_executable]) == 1, 'no running test executable processes'
  48.     pid = os.fork()
  49.     if pid == 0:
  50.         sys.stdin.close()
  51.         os.setsid()
  52.         os.execv(test_executable, [test_executable])
  53.         assert False, 'Could not execute ' + test_executable
  54.  
  55.     # wait until child process has execv()ed properly
  56.     while 'test-apport' in open('/proc/%i/cmdline' % pid).read():
  57.         time.sleep(0.1)
  58.     return pid
  59.  
  60. def check_crash(expect_coredump=True, expect_corefile=False, sig=signal.SIGSEGV, check_running=True, sleep=0):
  61.     global mode # hack to avoid passing the mode every time
  62.  
  63.     assert not os.path.exists('core'), 'no core dump in current directory'
  64.     pid = create_test_process(check_running)
  65.     if sleep > 0:
  66.         time.sleep(sleep)
  67.     os.kill(pid, sig)
  68.     result = os.waitpid(pid, 0)[1]
  69.     assert not os.WIFEXITED(result), 'test process did not exit normally'
  70.     assert os.WIFSIGNALED(result), 'test process died due to signal'
  71.     if expect_coredump and mode == 'kernel':
  72.         assert os.WCOREDUMP(result), 'result: 0x%02X should include WCOREDUMP' % result
  73.     else:
  74.         assert not os.WCOREDUMP(result), 'result: 0x%02X should not have WCOREDUMP' % result
  75.     assert os.WSTOPSIG(result) == 0, 'test process was not signaled to stop'
  76.     assert os.WTERMSIG(result) == sig, 'test process died due to proper signal'
  77.     # wait max 10 seconds for apport to finish
  78.     timeout = 50
  79.     while timeout >= 0:
  80.     if subprocess.call(['pidof', '-x', 'apport'], stdout=subprocess.PIPE) != 0:
  81.         break
  82.     time.sleep(0.2)
  83.     timeout -= 1
  84.     assert subprocess.call(['pidof', '-x', 'apport']) == 1, 'no running apport processes'
  85.     if check_running:
  86.         assert subprocess.call(['pidof', test_executable]) == 1, 'no running test executable processes'
  87.     if expect_corefile:
  88.         assert os.path.exists('core'), 'leaves wanted core file'
  89.         try:
  90.             # check that core file is valid
  91.             gdb = subprocess.Popen(['gdb', '--batch', '--ex', 'bt',
  92.                 test_executable, 'core'], stdout=subprocess.PIPE,
  93.                 stderr=subprocess.PIPE)
  94.             (out, err) = gdb.communicate()
  95.             assert gdb.returncode == 0
  96.             err = err.strip()
  97.             assert err == '' or \
  98.                 (err.startswith('warning') and len(err.splitlines()) == 1) , err
  99.         finally:
  100.             os.unlink('core')
  101.     else:
  102.         assert not os.path.exists('core'), 'leaves unexpected core file behind'
  103.  
  104. def check_safe_environment(env):
  105.     allowed_vars = ['SHELL', 'PATH', 'LANGUAGE', 'LANG', 'LC_CTYPE',
  106.         'LC_COLLATE', 'LC_TIME', 'LC_NUMERIC', 'LC_MONETARY', 'LC_MESSAGES',
  107.         'LC_PAPER', 'LC_NAME', 'LC_ADDRESS', 'LC_TELEPHONE', 'LC_MEASUREMENT',
  108.         'LC_IDENTIFICATION', 'LOCPATH']
  109.  
  110.     for l in env.splitlines():
  111.         (k, v) = l.split('=', 1)
  112.         assert k in allowed_vars, '%s is insensitive environment variable' % k
  113.  
  114. def get_tempdir_reports(dir):
  115.     '''Call apport.fileutils.get_all_reports() for a temporary report
  116.     directory.'''
  117.  
  118.     old_dir = apport.fileutils.report_dir
  119.     apport.fileutils.report_dir = dir
  120.     reports = apport.fileutils.get_all_reports()
  121.     apport.fileutils.report_dir = old_dir
  122.     return reports
  123.  
  124. #
  125. # main
  126. #
  127.  
  128. if len(sys.argv) != 2 or sys.argv[1] not in ('lib', 'kernel'):
  129.     print 'Usage: %s lib|kernel' % sys.argv[0]
  130.     sys.exit(1)
  131. mode = sys.argv[1]
  132.  
  133. all_passed = False
  134.  
  135. # we sometimes need a local report dir because we cannot access root's .lock file
  136. temp_report_dir = tempfile.mkdtemp() 
  137.  
  138. try:
  139.     core_pattern = open('/proc/sys/kernel/core_pattern').read().strip()
  140.     # check if kernel crashdump helper is already active
  141.     if mode == 'lib':
  142.         assert core_pattern[0] != '|', \
  143.                 'kernel crash dump helper is still active; please disable before running this test.'
  144.  
  145.         # set up temporary report directory
  146.         os.environ['APPORT_REPORT_DIR'] = temp_report_dir
  147.         apport.fileutils.report_dir = temp_report_dir
  148.         (fd, os.environ['APPORT_LOG_FILE']) = tempfile.mkstemp()
  149.         os.close(fd)
  150.  
  151.         # setup preload library
  152.         clean_preload_lib()
  153.         build_preload_lib()
  154.  
  155.         apport_path = 'bin/apport'
  156.     else:
  157.         assert core_pattern[0] == '|', \
  158.                 'kernel crash dump helper is not active; please enable before running this test.'
  159.         apport_path = core_pattern[1:].split()[0]
  160.  
  161.     assert apport.fileutils.get_all_reports() == [], 'please remove all crash reports from /var/crash/ for this test suite'
  162.  
  163.     # do not write core files for the first tests
  164.     resource.setrlimit(resource.RLIMIT_CORE, (0, -1))
  165.  
  166.     # move aside current ignore file
  167.     if os.path.exists(ifpath):
  168.     orig_ignore_file = ifpath + '.apporttest'
  169.     os.rename(ifpath, orig_ignore_file)
  170.  
  171.     print '* empty core dumps do not generate a report'
  172.     test_proc = create_test_process()
  173.     try:
  174.         app = subprocess.Popen([apport_path, str(test_proc), '42', '0'], 
  175.             env={'APPORT_REPORT_DIR': temp_report_dir}, close_fds=True,
  176.             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  177.         app.stdin.close()
  178.         assert app.wait() == 0, app.stderr.read()
  179.     finally:
  180.         os.kill(test_proc, 9)
  181.         os.waitpid(test_proc, 0)
  182.  
  183.     assert get_tempdir_reports(temp_report_dir) == [], 'no report created for empty core dump'
  184.  
  185.     if mode == 'lib':
  186.         print '* check test process creation/killing without apport'
  187.         check_crash(False)
  188.         assert apport.fileutils.get_all_reports() == [], 'no report created without apport'
  189.  
  190.     print '* check test process creation/killing with apport'
  191.     if mode == 'lib':
  192.         enable_preloadlib()
  193.     check_crash()
  194.  
  195.     # check crash report
  196.     report = os.path.join(apport.fileutils.report_dir, '%s.%i.crash' %
  197.         (test_executable.replace('/', '_'), os.getuid()))
  198.     assert apport.fileutils.get_all_reports() == [report], 'report was created'
  199.     st = os.stat(report)
  200.     assert stat.S_IMODE(st.st_mode) == 0600, 'report has correct permissions'
  201.  
  202.     print '* a subsequent crash does not alter unseen report'
  203.     check_crash()
  204.     st2 = os.stat(report)
  205.     assert st == st2, 'original unread report did not change'
  206.  
  207.     print '* a subsequent crash alters seen report'
  208.     apport.fileutils.mark_report_seen(report)
  209.     check_crash()
  210.     st2 = os.stat(report)
  211.     assert st != st2, 'original read report changed'
  212.  
  213.     print '* report has required fields'
  214.     pr = apport.Report()
  215.     pr.load(open(report))
  216.     assert set(required_fields).issubset(set(pr.keys())), 'report has required fields'
  217.     assert pr['ExecutablePath'] == test_executable
  218.     assert pr['ProcCmdline'] == test_executable
  219.     assert pr['Signal'] == '%i' % signal.SIGSEGV
  220.  
  221.     print '* dumped environment only has insensitive variables'
  222.     check_safe_environment(pr['ProcEnviron'])
  223.  
  224.     print '* collected system groups has nonempty user groups information'
  225.     assert pr['UserGroups']
  226.     print '* collected system groups are not those from root'
  227.     assert 'root' not in pr['UserGroups']
  228.  
  229.     apport.fileutils.delete_report(report)
  230.     assert apport.fileutils.get_all_reports() == [], \
  231.         'no reports present after deleting (present: %s)' % str(apport.fileutils.get_all_reports())
  232.  
  233.     print '* only one apport instance is ran at a time'
  234.     test_proc = create_test_process()
  235.     test_executable = '/bin/dd'
  236.     test_proc2 = create_test_process(False)
  237.     test_executable = '/bin/cat'
  238.     try:
  239.         app = subprocess.Popen([apport_path, str(test_proc), '42', '0'], 
  240.             env={'APPORT_REPORT_DIR': temp_report_dir}, close_fds=True,
  241.             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  242.  
  243.         app2 = subprocess.Popen([apport_path, str(test_proc2), '42', '0'], 
  244.             env={'APPORT_REPORT_DIR': temp_report_dir}, close_fds=True,
  245.             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  246.  
  247.         # app should wait indefinitely for stdin, while app2 should terminate
  248.         # immediately (give it 5 seconds)
  249.         timeout = 50
  250.         while timeout >= 0:
  251.             if app2.poll():
  252.                 break
  253.  
  254.             time.sleep(0.1)
  255.             timeout -= 1
  256.  
  257.         assert timeout > 0, 'second apport instance terminates immediately'
  258.         assert not app.poll(), 'first apport instance is still running'
  259.  
  260.         # properly terminate app and app2
  261.         app2.stdin.close()
  262.         app.stdin.write('boo')
  263.         app.stdin.close()
  264.  
  265.         assert app.wait() == 0, app.stderr.read()
  266.     finally:
  267.         os.kill(test_proc, 9)
  268.         os.waitpid(test_proc, 0)
  269.         os.kill(test_proc2, 9)
  270.         os.waitpid(test_proc2, 0)
  271.  
  272.     for r in get_tempdir_reports(temp_report_dir):
  273.         apport.fileutils.delete_report(r)
  274.  
  275.     print '* existing .lock file as dangling symlink does not create the file'
  276.     # prepare a symlink trap
  277.     lockpath = os.path.join(temp_report_dir, '.lock')
  278.     trappath = os.path.join(temp_report_dir, '0wned')
  279.     os.unlink(lockpath)
  280.     assert not os.path.exists(trappath)
  281.     os.symlink(trappath, lockpath)
  282.  
  283.     # now call apport
  284.     test_proc = create_test_process()
  285.  
  286.     try:
  287.         app = subprocess.Popen([apport_path, str(test_proc), '42', '0'], 
  288.             env={'APPORT_REPORT_DIR': temp_report_dir}, close_fds=True,
  289.             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  290.         app.stdin.write('boo')
  291.         app.stdin.close()
  292.  
  293.         assert app.wait() != 0, app.stderr.read()
  294.     finally:
  295.         os.kill(test_proc, 9)
  296.         os.waitpid(test_proc, 0)
  297.  
  298.     assert get_tempdir_reports(temp_report_dir) == [], 'no report created'
  299.     assert not os.path.exists(trappath), 'dangling .lock symlink created ' + trappath
  300.     # remove our trap again
  301.     os.unlink(lockpath)
  302.     # remove crash reports about apport itself (when the packaged version is
  303.     # ran from the test suite)
  304.     for r in apport.fileutils.get_all_reports():
  305.         apport.fileutils.delete_report(r)
  306.  
  307.     print '* non-packaged executables do not create a report'
  308.     orig_test_executable = test_executable
  309.     (fd, test_executable) = tempfile.mkstemp()
  310.     os.write(fd, open(orig_test_executable).read())
  311.     os.close(fd)
  312.     os.chmod(test_executable, 0755)
  313.     check_crash()
  314.     os.unlink(test_executable)
  315.     test_executable = orig_test_executable
  316.     assert apport.fileutils.get_all_reports() == [], \
  317.         'no reports present after a non-packaged crashed process (present: %s)' % \
  318.         str(apport.fileutils.get_all_reports())
  319.  
  320.     print '* apport ignores SIGQUIT'
  321.     check_crash(sig=signal.SIGQUIT)
  322.     assert apport.fileutils.get_all_reports() == [], \
  323.         'no reports present after SIGQUIT (present: %s)' % \
  324.         str(apport.fileutils.get_all_reports())
  325.  
  326.     print '* existence of user-inaccessible files does not leak'
  327.     orig_test_executable = test_executable
  328.     dir = tempfile.mkdtemp()
  329.     test_executable = os.path.join(dir, 'python') # set name to existing tool != self
  330.     exec_file = open(test_executable, 'w')
  331.     exec_file.write('#!/usr/bin/perl\nsystem("mv $0 $0.exe");\nsystem("ln -sf /etc/shadow $0");\n$0="..$0";\nsleep(10);\n')
  332.     exec_file.close()
  333.     os.chmod(test_executable, 0755)
  334.     check_crash(check_running=False, sleep=2)
  335.     os.unlink(test_executable)
  336.     os.unlink(test_executable+".exe")
  337.     os.rmdir(dir)
  338.     leak = os.path.join(apport.fileutils.report_dir, '_usr_bin_perl.%i.crash' %
  339.         (os.getuid()))
  340.     pr = apport.Report()
  341.     pr.load(open(leak))
  342.     # On a leak, no report is created since the executable path will be replaced
  343.     # by the symlink path, and it doesn't belong to any package.
  344.     assert pr['ExecutablePath'] == '/usr/bin/perl'
  345.     assert not pr.has_key('InterpreterPath')
  346.     apport.fileutils.delete_report(leak)
  347.     test_executable = orig_test_executable
  348.  
  349.     print '* non-packaged scripts do not create a report'
  350.     orig_test_executable = test_executable
  351.     (fd, test_executable) = tempfile.mkstemp()
  352.     os.write(fd, '#!/bin/sh\nkill -SEGV $$')
  353.     os.close(fd)
  354.     os.chmod(test_executable, 0755)
  355.     check_crash()
  356.     assert apport.fileutils.get_all_reports() == [], \
  357.         'no reports present after a non-packaged crashed script (present: %s)' % \
  358.         str(apport.fileutils.get_all_reports())
  359.  
  360.     # relative path case
  361.     old_cwd = os.getcwd()
  362.     try:
  363.         os.chdir(os.path.dirname(test_executable))
  364.         test_executable = './' + os.path.basename(test_executable)
  365.         check_crash()
  366.         os.unlink(test_executable)
  367.         test_executable = orig_test_executable
  368.     finally:
  369.         os.chdir(old_cwd)
  370.     assert apport.fileutils.get_all_reports() == [], \
  371.         'no reports present after a non-packaged crashed script with relative path(present: %s)' % \
  372.         str(apport.fileutils.get_all_reports())
  373.  
  374.     print '* limitation of flooding: iteration',
  375.     count = 0
  376.     while count < 7:
  377.         print count,
  378.         sys.stdout.flush()
  379.         check_crash()
  380.         if mode == 'lib':
  381.             time.sleep(1)
  382.         if not apport.fileutils.get_new_reports():
  383.             break
  384.         apport.fileutils.mark_report_seen(apport.fileutils.get_new_reports()[0])
  385.         count += 1
  386.     print
  387.     assert count >= 1, 'gets at least 2 repeated crashes'
  388.     assert count < 7, 'stops flooding after less than 7 repeated crashes'
  389.  
  390.     apport.fileutils.delete_report(report)
  391.     assert apport.fileutils.get_all_reports() == [], \
  392.         'no reports present after deleting (present: %s)' % str(apport.fileutils.get_all_reports())
  393.  
  394.     print '* core dump works for non-writable cwds'
  395.     old_cwd = os.getcwd()
  396.     try:
  397.         os.chdir('/')
  398.         check_crash()
  399.     finally:
  400.         os.chdir(old_cwd)
  401.     pr = apport.Report()
  402.     assert os.path.exists(report)
  403.     pr.load(open(report))
  404.     assert set(required_fields).issubset(set(pr.keys()))
  405.     apport.fileutils.delete_report(report)
  406.     assert apport.fileutils.get_all_reports() == [], \
  407.         'no reports present after deleting (present: %s)' % str(apport.fileutils.get_all_reports())
  408.  
  409.     print '* non-packaged executables create core dumps on proper ulimits'
  410.     orig_test_executable = test_executable
  411.     (fd, test_executable) = tempfile.mkstemp()
  412.     os.write(fd, open(orig_test_executable).read())
  413.     os.close(fd)
  414.  
  415.     os.chmod(test_executable, 0755)
  416.     resource.setrlimit(resource.RLIMIT_CORE, (1, -1))
  417.     check_crash(expect_corefile=False)
  418.     apport.fileutils.delete_report(report)
  419.     resource.setrlimit(resource.RLIMIT_CORE, (10, -1))
  420.     check_crash(expect_corefile=False)
  421.     apport.fileutils.delete_report(report)
  422.     resource.setrlimit(resource.RLIMIT_CORE, (10000, -1))
  423.     check_crash(expect_corefile=True)
  424.     apport.fileutils.delete_report(report)
  425.     resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
  426.     check_crash(expect_corefile=True)
  427.     apport.fileutils.delete_report(report)
  428.  
  429.     print '* non-packaged executables create core dumps on proper ulimits for SIGABRT'
  430.     os.chmod(test_executable, 0755)
  431.     resource.setrlimit(resource.RLIMIT_CORE, (1, -1))
  432.     check_crash(expect_corefile=False, sig=signal.SIGABRT)
  433.     apport.fileutils.delete_report(report)
  434.     resource.setrlimit(resource.RLIMIT_CORE, (10, -1))
  435.     check_crash(expect_corefile=False, sig=signal.SIGABRT)
  436.     apport.fileutils.delete_report(report)
  437.     resource.setrlimit(resource.RLIMIT_CORE, (10000, -1))
  438.     check_crash(expect_corefile=True, sig=signal.SIGABRT)
  439.     apport.fileutils.delete_report(report)
  440.     resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
  441.     check_crash(expect_corefile=True, sig=signal.SIGABRT)
  442.     apport.fileutils.delete_report(report)
  443.  
  444.     os.unlink(test_executable)
  445.     test_executable = orig_test_executable
  446.  
  447.     print '* packaged executables create core dumps on proper ulimits'
  448.     resource.setrlimit(resource.RLIMIT_CORE, (1, -1))
  449.     check_crash(expect_corefile=False)
  450.     apport.fileutils.delete_report(report)
  451.     resource.setrlimit(resource.RLIMIT_CORE, (10, -1))
  452.     check_crash(expect_corefile=False)
  453.     apport.fileutils.delete_report(report)
  454.     resource.setrlimit(resource.RLIMIT_CORE, (10000, -1))
  455.     check_crash(expect_corefile=True)
  456.     apport.fileutils.delete_report(report)
  457.     resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
  458.     check_crash(expect_corefile=True)
  459.  
  460.     print '* crashes create core dumps with an existing crash report'
  461.     check_crash(expect_corefile=True)
  462.     apport.fileutils.delete_report(report)
  463.  
  464.     print '* packaged executables create core dumps on proper ulimits for SIGABRT'
  465.     resource.setrlimit(resource.RLIMIT_CORE, (1, -1))
  466.     check_crash(expect_corefile=False, sig=signal.SIGABRT)
  467.     resource.setrlimit(resource.RLIMIT_CORE, (10, -1))
  468.     check_crash(expect_corefile=False, sig=signal.SIGABRT)
  469.     resource.setrlimit(resource.RLIMIT_CORE, (10000, -1))
  470.     check_crash(expect_corefile=True, sig=signal.SIGABRT)
  471.     apport.fileutils.delete_report(report)
  472.     resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
  473.     check_crash(expect_corefile=True, sig=signal.SIGABRT)
  474.     apport.fileutils.delete_report(report)
  475.  
  476.     print '* core dumps are capped on available memory size',
  477.     # determine how much data we have to pump into apport in order to make sure
  478.     # that it will refuse the core dump
  479.     r = apport.Report()
  480.     r.load(open('/proc/meminfo'))
  481.     totalmb = long(r['MemFree'].split()[0]) + long(r['Cached'].split()[0])
  482.     totalmb /= 1024
  483.     r = None
  484.  
  485.     test_proc = create_test_process()
  486.     try:
  487.         app = subprocess.Popen([apport_path, str(test_proc), '42', '0'], 
  488.             env={'APPORT_REPORT_DIR': temp_report_dir}, close_fds=True,
  489.             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  490.         # pipe an entire total memory size worth of spaces into it, which must be
  491.         # bigger than the 'usable' memory size. apport should digest that and the
  492.         # report should not have a core dump; NB that this should error out
  493.         # with a SIGPIPE when apport aborts reading from stdin
  494.         onemb = ' ' * 1048576
  495.         while totalmb > 0:
  496.             if totalmb & 31 == 0:
  497.                 sys.stdout.write('.')
  498.                 sys.stdout.flush()
  499.             try:
  500.                 app.stdin.write(onemb)
  501.             except IOError, e:
  502.                 if e.errno == errno.EPIPE:
  503.                     break
  504.                 else:
  505.                     raise
  506.             totalmb -= 1
  507.         print
  508.         app.stdin.close()
  509.         assert app.wait() == 0, app.stderr.read()
  510.         onemb = None
  511.     finally:
  512.         os.kill(test_proc, 9)
  513.         os.waitpid(test_proc, 0)
  514.  
  515.     reports = get_tempdir_reports(temp_report_dir)
  516.     assert len(reports) == 1, 'report was created'
  517.  
  518.     pr = apport.Report()
  519.     pr.load(open(reports[0]))
  520.     os.unlink(reports[0])
  521.  
  522.     assert pr['Signal'] == '42'
  523.     assert pr['ExecutablePath'] == test_executable
  524.     assert not pr.has_key('CoreDump'), 'report does not have core dump'
  525.  
  526.  
  527.     print '* binary blacklisting works'
  528.     pr.mark_ignore()
  529.     check_crash()
  530.     assert apport.fileutils.get_all_reports() == [], \
  531.         'no reports present for ignored binary'
  532.  
  533.     all_passed = True
  534.  
  535. finally:
  536.     # clean up our ignore file
  537.     if os.path.exists(ifpath):
  538.     os.unlink(ifpath)
  539.     if orig_ignore_file:
  540.     os.rename(orig_ignore_file, ifpath)
  541.  
  542.     # clean up temporary work directory
  543.     try:
  544.         apport.fileutils.delete_report(report)
  545.     except:
  546.         pass
  547.     shutil.rmtree(temp_report_dir)
  548.     if mode == 'lib':
  549.         clean_preload_lib()
  550.     if os.environ.has_key('APPORT_LOG_FILE'):
  551.         if not all_passed:
  552.             print '----- apport log file -----'
  553.             print open(os.environ['APPORT_LOG_FILE']).read()
  554.         os.unlink(os.environ['APPORT_LOG_FILE'])
  555.